package logic

import (
	"context"
	"fmt"
	"product2/model/redis"

	"product2/userrpc/internal/svc"
	"product2/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikelistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikelistLogic {
	return &LikelistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikelistLogic) Likelist(in *userrpc.LikelistRequest) (*userrpc.LikelistResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Client.ZRevRangeWithScores("like", 0, 9)
	var product []*userrpc.Likelist
	for _, i2 := range scores.Val() {
		list := userrpc.Likelist{
			Name:   i2.Member.(string),
			Number: int64(i2.Score),
		}
		product = append(product, &list)
	}
	fmt.Println(scores)
	return &userrpc.LikelistResponse{List: product}, nil
}
